package com.mawendaxiong.blogprovider.blogType.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.mawendaxiong.blogprovider.blogType.entity.BlogType;
import com.mawendaxiong.blogprovider.blogType.service.BlogTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.UUID;

@RestController
@RequestMapping("/blogType/admin")
@Slf4j
public class BlogTypeAdminController extends BlogTypeController {
    @Autowired
    private BlogTypeService service;

    @PostMapping("addBlogType")
    public String addBlogType(@RequestBody BlogType vo) {
        vo.setKid(UUID.randomUUID().toString().replace("-", ""));
        boolean isSave = service.save(vo);
        if (isSave) {
            return "success";
        } else {
            return "fail";
        }
    }

    @PostMapping("updateBlogType")
    public String updateBlogType(@RequestBody BlogType vo) {
        int isUpdate = service.updateBlogType(vo);
        if (isUpdate > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @PostMapping("deleteBlogType")
    public String deleteBlogType(@RequestParam String kid) {
        BlogType blogType = new BlogType();
        blogType.setKid(kid);
        blogType.setIsDel(1);
        int isUpdate = service.updateBlogType(blogType);
        if (isUpdate > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
}
